package com.choosefine.it.project.controller;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.project.model.vo.*;
import com.choosefine.it.project.service.ProjectInfoForShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Comments：商城接口
 * Author：maojun
 * Create Date：2017/2/21
 * Modified By：
 * Modified Date：
 * Why & What is modified：
 * Version：v1.0
 */
@RestController
@Api(value = "商城接口相关",description = "毛俊")
@RequestMapping("/ProjectInfoForShop")
public class ProjectInfoForShopController extends BaseController {
    @Autowired
    ProjectInfoForShopService projectInfoForShopService;

    @ApiOperation(value = "根据项目code查询项目信息",response = ProjectInfoForShopVO.class)
    @ApiImplicitParam(name = "projectCode",value = "项目code",required = true,dataType = "String",paramType = "path")
    @RequestMapping(value = "/getInfoByProjectCode/{projectCode}",method = RequestMethod.GET)
    public  String getInfoByProjectCode(@PathVariable String projectCode){
        String result=null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(projectCode != null && !"".equals(projectCode)){
            params.put("projectCode",projectCode);
        }
       List<ProjectInfoForShopVO> list=projectInfoForShopService.getInfoByProjectCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;

    }
    @ApiOperation(value = "根据分包班组承包人租户编号和项目code查询班组id和分包承包人",response = TeamInfoListVO.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "projectCode",value = "项目code",required = true,dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "teamUserCode",value = "分包班组承包人租户编号",required = true,dataType = "String",paramType = "path")})
    @RequestMapping(value = "/getTeamInfoByTeamUserCode/{projectCode}/{teamUserCode}",method = RequestMethod.GET)
    public String getTeamInfoByTeamUserCode(@PathVariable String projectCode,
                                            @PathVariable String teamUserCode){
        String result=null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(projectCode != null && !"".equals(projectCode)){
            params.put("projectCode",projectCode);
        }
        if(teamUserCode != null && !"".equals(teamUserCode)){
            params.put("teamUserCode",teamUserCode);
        }
        List<TeamInfoListVO> list=projectInfoForShopService.getTeamInfoByTeamUserCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }
    @ApiOperation(value = "根据分包班组承包人租户编号查询项目列表（项目code和项目名称）",response = ProjectInfoListVO.class)
    @ApiImplicitParam(name = "teamUserCode",value = "分包班组承包人租户编号",required = true,dataType = "String",paramType = "path")
    @RequestMapping(value = "/getProjectInfoByTeamUserCode/{teamUserCode}",method = RequestMethod.GET)
    public String getProjectInfoByTeamUserCode(@PathVariable String teamUserCode){
        String result=null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(teamUserCode != null && !"".equals(teamUserCode)){
            params.put("teamUserCode",teamUserCode);
        }
        List<ProjectInfoListVO> list=projectInfoForShopService.getProjectInfoByTeamUserCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }
    @ApiOperation(value = "根据项目经理租户编号查询项目列表（项目code和项目名称）",response = ProjectInfoListVO.class)
    @ApiImplicitParam(name = "managerUserCode",value = "项目经理租户编号",required = true,dataType = "String",paramType = "path")
    @RequestMapping(value = "/getProjectInfoByManagerUserCode/{managerUserCode}",method = RequestMethod.GET)
    public String getProjectInfoByManagerUserCode(@PathVariable String managerUserCode){
        String result=null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(managerUserCode != null && !"".equals(managerUserCode)){
            params.put("managerUserCode",managerUserCode);
        }
        List<ProjectInfoListVO> list=projectInfoForShopService.getProjectInfoByManagerUserCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }
    @ApiOperation(value = "根据建筑公司code和项目名称模糊查找项目列表 （返回项目名称和项目code列表）",response = ProjectInfoListVO.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "companyCode",value = "建筑公司code",required = true,dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "projectName",value = "项目名称",required = false,dataType = "String",paramType = "query")})
    @RequestMapping(value = "/getProjectInfoByProjectName/{companyCode}",method = RequestMethod.GET)
    public String  getProjectInfoByProjectName(@PathVariable String companyCode,String projectName){
        String result=null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(companyCode != null && !"".equals(companyCode)){
            params.put("companyCode",companyCode);
        }
        if(projectName != null && !"".equals(projectName)){
            params.put("projectName",projectName);
        }
        List<ProjectInfoListVO> list=projectInfoForShopService.getProjectInfoByProjectName(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }

    @ApiOperation(value = "根据建筑公司名称模糊查找公司列表（返回公司名称和公司的租户编号列表）",response = CompanyInfoVO.class)
    @ApiImplicitParam(name = "companyName",value = "建筑公司名称",required = true,dataType = "String",paramType = "path")
    @RequestMapping(value = "/getCompanyInfoByCompanyName/{companyName}",method = RequestMethod.GET)
    public String  getCompanyInfoByCompanyName(@PathVariable String companyName){
        String result=null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(companyName != null && !"".equals(companyName)){
            params.put("companyName",companyName);
        }
        List<CompanyInfoVO> list=projectInfoForShopService.getCompanyInfoByCompanyName(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }
    @ApiOperation(value = "根据班组租户编号和项目编号查询合作商家租户编号集合")
    @ApiImplicitParams({@ApiImplicitParam(name = "teamUserCode",value = "班组租户编号",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "projectCode",value = "项目编号",required = false,dataType = "String",paramType = "query")})
    @RequestMapping(value = "/getCooperateCodeListByTeamCode",method = RequestMethod.GET)
    public String getCooperateCodeListByTeamCode( String teamUserCode, String projectCode){
        String result = null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(teamUserCode != null && !"".equals(teamUserCode)){
            params.put("teamUserCode",teamUserCode);
        }
        if(projectCode !=null && !"".equals(projectCode)){
            params.put("projectCode",projectCode);
        }
        List list=projectInfoForShopService.getCooperateCodeListByTeamCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }

    @ApiOperation(value = "根据项目经理租户编号和项目编号查询合作商家租户编号集合")
    @ApiImplicitParams({@ApiImplicitParam(name = "managerUserCode",value = "项目经理租户编号",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "projectCode",value = "项目编号",required = false,dataType = "String",paramType = "query")})
    @RequestMapping(value = "/getCooperateCodeListByManagerCode",method = RequestMethod.GET)
    public String getCooperateCodeListByManagerCode(String managerUserCode, String projectCode){
        String result = null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(managerUserCode != null && !"".equals(managerUserCode)){
            params.put("managerUserCode",managerUserCode);
        }
        if(projectCode !=null && !"".equals(projectCode)){
            params.put("projectCode",projectCode);
        }
        List list=projectInfoForShopService.getCooperateCodeListByManagerCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }

    @ApiOperation(value = "根据班组租户编号和项目编号查询项目的合作商家及对应项目code和名称",response = ProjectWithCooperationInfoVO.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "teamUserCode",value = "班组租户编号",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "projectCode",value = "项目编号",required = false,dataType = "String",paramType = "query")})
    @RequestMapping(value = "/getProjectCodeAndNameByTeamCode",method = RequestMethod.GET)
    public String getProjectCodeAndNameByTeamCode( String teamUserCode, String projectCode){
        String result = null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(teamUserCode != null && !"".equals(teamUserCode)){
            params.put("teamUserCode",teamUserCode);
        }
        if(projectCode !=null && !"".equals(projectCode)){
            params.put("projectCode",projectCode);
        }
        List<ProjectWithCooperationInfoVO> list=projectInfoForShopService.getProjectCodeAndNameByTeamCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }

    @ApiOperation(value = "根据项目经理租户编号和项目编号查询项目的合作商家及对应项目code和名称",response = ProjectWithCooperationInfoVO.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "managerUserCode",value = "项目经理租户编号",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "projectCode",value = "项目编号",required = false,dataType = "String",paramType = "query")})
    @RequestMapping(value = "/getProjectCodeAndNameByManagerCode",method = RequestMethod.GET)
    public String getProjectCodeAndNameByManagerCode(String managerUserCode, String projectCode){
        String result = null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(managerUserCode != null && !"".equals(managerUserCode)){
            params.put("managerUserCode",managerUserCode);
        }
        if(projectCode !=null && !"".equals(projectCode)){
            params.put("projectCode",projectCode);
        }
        List<ProjectWithCooperationInfoVO> list=projectInfoForShopService.getProjectCodeAndNameByManagerCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }
    @ApiOperation(value = "根据建筑公司code查询合作商家及对应项目code和名称",response = ProjectWithCooperationInfoVO.class)
    @ApiImplicitParam(name = "companyCode",value = "建筑公司code",required = true,dataType = "String",paramType = "query")
    @RequestMapping(value = "/getProjectCodeAndNameByCompanyCode",method = RequestMethod.GET)
    public String getProjectCodeAndNameByCompanyCode(@RequestParam String companyCode){
        String result = null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(companyCode != null && !"".equals(companyCode)){
            params.put("companyCode",companyCode);
        }
        List<ProjectWithCooperationInfoVO> list=projectInfoForShopService.getProjectCodeAndNameByCompanyCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }
    @ApiOperation(value = "根据分包单位code查找合作商家及对应项目code和名称",response = ProjectWithCooperationInfoVO.class)
    @ApiImplicitParam(name = "subUnitCode",value = "分包单位租户编号",required = true,dataType = "String",paramType = "query")
    @RequestMapping(value = "/getProjectCodeAndNameBySubUnitCode",method = RequestMethod.GET)
    public String getProjectCodeAndNameBySubUnitCode(@RequestParam String subUnitCode){
        String result = null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(subUnitCode != null && !"".equals(subUnitCode)){
            params.put("subUnitCode",subUnitCode);
        }
        List<ProjectWithCooperationInfoVO> list=projectInfoForShopService.getProjectCodeAndNameBySubUnitCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }

    @ApiOperation(value = "根据分包单位租户编号查找班组",response = TeamCodeAndNameVO.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "unitCode",value = "分包单位租户编号",required = true,dataType = "String",paramType = "query")})
    @RequestMapping(value = "/getTeamInfoByUnitCode",method = RequestMethod.GET)
    public String getTeamInfoByUnitCode(@RequestParam String unitCode){
        String result = null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(unitCode != null && !"".equals(unitCode)){
            params.put("unitCode",unitCode);
        }
        List<TeamCodeAndNameVO> list=projectInfoForShopService.getTeamInfoByUnitCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }
    @ApiOperation(value = "根据分包单位编号或者结合分包单位下面班组code查找下面项目",response = ProjectInfoListVO.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "unitCode",value = "分包单位租户编号",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "teamUserCode",value = "项目编号",required = false,dataType = "String",paramType = "query")})
    @RequestMapping(value = "/getTeamInfoByUnitCodeOrteamUserCode",method = RequestMethod.GET)
    public String getTeamInfoByUnitCodeOrteamUserCode(@RequestParam String unitCode,String teamUserCode){
        String result = null;
        Map<String,Object> params=new HashMap<String,Object>();
        if(unitCode != null && !"".equals(unitCode)){
            params.put("unitCode",unitCode);
        }
        if(teamUserCode != null && !"".equals(teamUserCode)){
            params.put("teamUserCode",teamUserCode);
        }
        List<ProjectInfoListVO> list=projectInfoForShopService.getTeamInfoByUnitCodeOrteamUserCode(params);
        if(list.size() > 0){
            result = responseArraySuccess(list);
        } else {
            result = responseFail(ResultCode.FAILED, ResultCode.MSG_DATA_ISEMPTY);
        }
        return result;
    }
}
